#include <tsin/util/Resolution.hpp>

using namespace tsin;

int Resolution::resolutionX(StandardResolution r)
{
        switch (r) {
        case r640x480:  return 640;
        case r800x450:  return 800;
        }
        return 0;
}

int Resolution::resolutionY(StandardResolution r)
{
        switch (r) {
        case r640x480:  return 480;
        case r800x450:  return 450;
        }
        return 0;
}

float Resolution::internalRangeX(StandardResolution r)
{
        return resolutionX(r) / RSLT_FACTOR;
}

float Resolution::internalRangeY(StandardResolution r)
{
        return resolutionY(r) / RSLT_FACTOR;
}

int Resolution::coord2pixelX(StandardResolution r, float coord)
{
        float range = internalRangeX(r);
        return (int)((coord + range / 2) / range * resolutionX(r));
}

int Resolution::coord2pixelY(StandardResolution r, float coord)
{
        float range = internalRangeY(r);
        return (int)((coord + range / 2) / range * resolutionY(r));
}

float Resolution::pixel2coordX(StandardResolution r, int pixel)
{
        float range = internalRangeX(r);
        return ((float)pixel) / resolutionX(r) * range - range / 2;
}

float Resolution::pixel2coordY(StandardResolution r, int pixel)
{
        float range = internalRangeY(r);
        return ((float)pixel) / resolutionY(r) * range - range / 2;
}

int Resolution::range2pixelX(StandardResolution r, float range)
{
        return (int)(range / internalRangeX(r) * resolutionX(r));
}

int Resolution::range2pixelY(StandardResolution r, float range)
{
        return (int)(range / internalRangeY(r) * resolutionY(r));
}

float Resolution::pixel2rangeX(StandardResolution r, int pixel)
{
        return ((float)pixel) / resolutionX(r) * internalRangeX(r);
}

float Resolution::pixel2rangeY(StandardResolution r, int pixel)
{
        return ((float)pixel) / resolutionY(r) * internalRangeY(r);
}